using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EngineOfEvermore.Common;

namespace EngineOfEvermore.Editor.Common
{
    public class MinimalSceneGraphContext
    {
        class InternalServiceProviderImpl : IServiceProvider
        {
            Dictionary<Type, Object> _services = new Dictionary<Type, Object>();

            public Object GetService( Type serviceType )
            {
                Object service;

                if ( _services.TryGetValue( serviceType, out service ) )
                {
                    return service;
                }

                return null;
            }

            public void AddService( Type serviceType, Object service )
            {
                _services[serviceType] = service;
            }
        }

        TimeContext _timeContext;
        FrameUpdater _updater;
        InternalServiceProviderImpl _serviceProvider;
        
        public MinimalSceneGraphContext()
        {
            _timeContext = new TimeContext();
            _updater = new FrameUpdater();

            _serviceProvider = new InternalServiceProviderImpl();

            _serviceProvider.AddService( typeof( ITimeContext ), _timeContext ); 
        }

        public IServiceProvider ServiceProvider
        {
            get { return _serviceProvider; }
        }

        public int UpdaterTargetFps
        {
            get { return _updater.TargetFps; }
            set { _updater.TargetFps = value; }
        }

        public float CurrentTime
        {
            get { return _timeContext.CurrentTime; }
        }

        public void UpdateTimeContext()
        {
            _updater.Update( _timeContext.Update );
        }
    }
}
